home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / misc / xref_v1.1.lha / XRef / Tools / source / expungexref.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-09  |  7.0 KB  |  272 lines

  1. ;/* execute me to make with SAS 6.x
  2. sc NOSTKCHK CSRC expungexref.c OPT IGNORE=73
  3. slink lib:c.o expungexref.o //Goodies/extrdargs/extrdargs.o TO /c/expungexref SMALLDATA SMALLCODE NOICONS LIB lib:amiga.lib lib:sc.lib /lib/xrefsupport.lib
  4. quit
  5. */
  6.  
  7. /*
  8. ** $PROJECT: XRef-Tools
  9. **
  10. ** $VER: expungexref.c 1.7 (24.09.94) 
  11. **
  12. ** by
  13. **
  14. ** Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
  15. **
  16. ** (C) Copyright 1994
  17. ** All Rights Reserved !
  18. **
  19. ** $HISTORY:
  20. **
  21. ** 24.09.94 : 001.007 :  locked info added
  22. ** 07.09.94 : 001.006 :  workbench support added (FinalReadArgs())
  23. ** 03.09.94 : 001.005 :  VERBOSE option added
  24. ** 06.07.94 : 001.004 :  xref.library function names changed
  25. ** 28.05.94 : 001.003 :  now use the tags function
  26. ** 18.05.94 : 001.002 :  file option and autodoc added
  27. ** 04.05.94 : 001.001 :  tags changed and force option added
  28. ** 02.05.94 : 000.001 :  initial
  29. */
  30.  
  31. /* ------------------------------- includes ------------------------------- */
  32.  
  33. #include "Def.h"
  34.  
  35. #include <libraries/xref.h>
  36. #include <proto/xref.h>
  37.  
  38. #include <register.h>
  39. #include <debug.h>
  40.  
  41. #include "/lib/xrefsupport.h"
  42.  
  43. #include "expungexref_rev.h"
  44.  
  45. struct ExpungeHookData
  46. {
  47.    struct Buffer *Buffer;
  48.    ULONG Locked;
  49.    ULONG Expunged;
  50.    BOOL Verbose;
  51.    struct Library *XRefBase;
  52. };
  53.  
  54. /* ---------------------------- version string ---------------------------- */
  55.  
  56. static char *version = VERSTAG;
  57. static char *prgname = "ExpungeXRef";
  58.  
  59. /* ------------------------------- AutoDoc -------------------------------- */
  60.  
  61. /*FS*/ /*"AutoDoc"*/
  62. /*GB*** XRef-Tools/ExpungeXRef ***********************************************
  63.  
  64. $VER: ExpungeXRef.doc
  65.  
  66. NAME
  67.     ExpungeXRef - expunge a given file,category or all xreffiles
  68.  
  69. TEMPLATE
  70.     CATEGORY,FILE/K,FORCE/S,VERBOSE/S
  71.  
  72. FORMAT
  73.     ExpungeXRef [[CATEGORY] category] [FILE xreffile] [FORCE] [VERBOSE]
  74.  
  75. FUNCTION
  76.     this command expunges a/some xreffiles from memory.If no category or
  77.     file is specified all xreffiles are removed. If you turn on the switch
  78.     FORCE, xreffiles are also removed, which are locked.
  79.  
  80. INPUTS
  81.     CATEGORY (STRING) - category of xreffiles to expunge. Can be a pattern.
  82.  
  83.     FILE (STRING) - only expunge the file given here
  84.  
  85.     FORCE (BOOLEAN) - expunge also such files, which are protected via the
  86.         LOCK mechanism
  87.  
  88.     VERBOSE (BOOLEAN) - show each file, which is expunged !
  89.  
  90. EXAMPLE
  91.     the following example expunges only the xreffile mytools.xref in the
  92.     global xref drawer , even it is locked or not :
  93.  
  94.        ExpungeXRef FILE mytools.xref FORCE
  95.  
  96. SEE ALSO
  97.     LoadXRef, xref.library/XR_ExpungeXRef(), xref.library/XR_LoadXRef()
  98.  
  99. HISTORY
  100.     ExpungeXRef 1.7 (24.9.94) :
  101.         - now displays xreffiles, which aren't expunged due to a lock
  102.  
  103.     ExpungeXRef 1.6 (7.9.94) :
  104.         - workbench support added
  105.  
  106.     ExpungeXRef 1.5 (3.9.94) :
  107.         - VERBOSE option added
  108.  
  109.     ExpungeXRef 1.4 (6.7.94) :
  110.         - xref.library function names changed
  111.  
  112.     ExpungeXRef 1.3 (28.5.94) :
  113.         - FILE argument added
  114.  
  115. *****************************************************************************/
  116. /*FE*/
  117.  
  118. /* ------------------------- template definition -------------------------- */
  119.  
  120. #define USETAG(tag,check)     ((check) ? (tag) : TAG_IGNORE)
  121.  
  122. #define template "CATEGORY,FILE/K,FORCE/S,VERBOSE/S"
  123.  
  124. enum {
  125.    ARG_CATEGORY,
  126.    ARG_FILE,
  127.    ARG_FORCE,
  128.    ARG_VERBOSE,
  129.    ARG_MAX};
  130.  
  131. /* ---------------------- expunge callback function ----------------------- */
  132.  
  133. RegCall GetA4 ULONG expungehook(REGA0 struct Hook *hook,REGA2 struct XRefFileNode *xref,REGA1 struct xrmExpunge *msg)
  134. {
  135.    if(msg->Msg == XRM_EXPUNGE)
  136.    {
  137.       struct ExpungeHookData *expdata = (struct ExpungeHookData *) hook->h_Data;
  138.       BOOL force  = (GetTagData(XREFA_Lock,XREF_LOCK,msg->exp_Attrs) == XREF_UNLOCK);
  139.       BOOL lock;
  140.  
  141.       #define XRefBase  expdata->XRefBase
  142.  
  143.       if(GetXRefFileAttrs(xref,XREFA_Lock,&lock,
  144.                                TAG_DONE) == 1)
  145.       {
  146.          if(force || !lock)
  147.          {
  148.             if(expdata->Verbose)
  149.                mysprintf(expdata->Buffer,"%s expunged !\n",xref->xrfn_Node.ln_Name);
  150.  
  151.             expdata->Expunged++;
  152.          } else
  153.          {
  154.             if(expdata->Verbose)
  155.                mysprintf(expdata->Buffer,"%s not expunged due to lock !\n",xref->xrfn_Node.ln_Name);
  156.  
  157.             expdata->Locked++;
  158.          }
  159.       }
  160.  
  161.       #undef XRefBase
  162.  
  163.       return(1);
  164.    }
  165.  
  166.    return(0);
  167. }
  168.  
  169. /* --------------------------- main entry point --------------------------- */
  170.  
  171. int main(int ac,char *av[])
  172. {
  173.    struct ExtRDArgs eargs = {NULL};
  174.    struct Library *XRefBase;
  175.  
  176.    struct Hook hook = {NULL};
  177.    ULONG para[ARG_MAX];
  178.    LONG err;
  179.    STRPTR obj = prgname;
  180.  
  181.    LONG i;
  182.  
  183.    hook.h_Entry = (HOOKFUNC) expungehook;
  184.  
  185.    /* clear args buffer */
  186.    for(i = 0 ; i < ARG_MAX ; i++)
  187.       para[i] = 0;
  188.  
  189.    eargs.erda_Template      = template;
  190.    eargs.erda_Parameter     = para;
  191.    eargs.erda_FileParameter = ARG_FILE;
  192.  
  193.    if((err = ExtReadArgs(ac,av,&eargs)) == 0)
  194.    {
  195.       obj = "xref.library";
  196.       if(XRefBase = OpenLibrary(obj,0))
  197.       {
  198.          struct Buffer *buf;
  199.  
  200.          if((buf = AllocMem(sizeof(struct Buffer),MEMF_ANY)))
  201.          {
  202.             struct ExpungeHookData expdata = {NULL};
  203.  
  204.             expdata.Buffer   = buf;
  205.             expdata.Verbose  = para[ARG_VERBOSE];
  206.             expdata.XRefBase = XRefBase;
  207.  
  208.             buf->b_Ptr  = buf->b_Buffer;
  209.             hook.h_Data = &expdata;
  210.  
  211.             obj = prgname;
  212.  
  213.             XR_ExpungeXRefTags(USETAG(XREFA_Category,!para[ARG_FILE] )  , para[ARG_CATEGORY],
  214.                                USETAG(XREFA_File    , para[ARG_FILE] )  , para[ARG_FILE],
  215.                                USETAG(XREFA_Lock    , para[ARG_FORCE])  , XREF_UNLOCK,
  216.                                XREFA_XRefHook                           , &hook,
  217.                                TAG_DONE);
  218.  
  219.             if(!para[ARG_VERBOSE])
  220.             {
  221.                mysprintf(buf,"%ld xreffiles expunged !\n",(APTR) expdata.Expunged);
  222.  
  223.                if(expdata.Locked)
  224.                   mysprintf(buf,"\n%ld xreffiles not expunged due to lock !\n",(APTR) expdata.Locked);
  225.             } else if(expdata.Expunged == 0)
  226.             {
  227.                mysprintf(buf,"no xreffiles expunged !\n",NULL);
  228.  
  229.                if(expdata.Locked)
  230.                   mysprintf(buf,"\n%ld xreffiles not expunged due to lock !\n",(APTR) expdata.Locked);
  231.             }  
  232.  
  233.             if(ac == 0)
  234.             {
  235.                struct EasyStruct es = {
  236.                   sizeof(struct EasyStruct),
  237.                   0,
  238.                   NULL,
  239.                   NULL,
  240.                   "Ok"};
  241.  
  242.                es.es_Title      = prgname;
  243.                es.es_TextFormat = buf->b_Buffer;
  244.  
  245.                EasyRequest(NULL,&es,NULL,NULL);
  246.             } else
  247.                PutStr(buf->b_Buffer);
  248.  
  249.             FreeMem(buf,sizeof(struct Buffer));
  250.          }
  251.          CloseLibrary(XRefBase);
  252.       }
  253.    }
  254.    ExtFreeArgs(&eargs);
  255.  
  256.    if(!err)
  257.       err = IoErr();
  258.  
  259.    if(err)
  260.    {
  261.       if(ac == 0)
  262.          showerror(prgname,obj,err);
  263.       else
  264.          PrintFault(err,obj);
  265.       return(RETURN_ERROR);
  266.    }
  267.  
  268.    return(RETURN_OK);
  269. }
  270.  
  271.  
  272.